<?php

/**
 * ProductOrder form base class.
 *
 * @method ProductOrder getObject() Returns the current form's model object
 *
 * @package    tsantek-shop
 * @subpackage form
 * @author     Tomislav Šantek
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseProductOrderForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'           => new sfWidgetFormInputHidden(),
      'generated_id' => new sfWidgetFormInputText(),
      'basket_id'    => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Basket'), 'add_empty' => false)),
      'user_id'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'add_empty' => true)),
      'shop_id'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Shop'), 'add_empty' => false)),
      'order_data'   => new sfWidgetFormInputText(),
      'comment'      => new sfWidgetFormTextarea(),
      'status'       => new sfWidgetFormChoice(array('choices' => array('recieved' => 'recieved', 'waiting_payment' => 'waiting_payment', 'in_transaction' => 'in_transaction', 'transaction_failed' => 'transaction_failed', 'finalized' => 'finalized', 'canceled' => 'canceled'))),
      'created_at'   => new sfWidgetFormDateTime(),
      'updated_at'   => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'id'           => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'generated_id' => new sfValidatorString(array('max_length' => 22)),
      'basket_id'    => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Basket'))),
      'user_id'      => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'required' => false)),
      'shop_id'      => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Shop'))),
      'order_data'   => new sfValidatorPass(array('required' => false)),
      'comment'      => new sfValidatorString(array('max_length' => 1000)),
      'status'       => new sfValidatorChoice(array('choices' => array(0 => 'recieved', 1 => 'waiting_payment', 2 => 'in_transaction', 3 => 'transaction_failed', 4 => 'finalized', 5 => 'canceled'), 'required' => false)),
      'created_at'   => new sfValidatorDateTime(),
      'updated_at'   => new sfValidatorDateTime(),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorDoctrineUnique(array('model' => 'ProductOrder', 'column' => array('basket_id')))
    );

    $this->widgetSchema->setNameFormat('product_order[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'ProductOrder';
  }

}
